package com.ylb.rent.filter;

import com.ylb.rent.util.R;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @AUTHOR:游李滨
 * @DATE:2023/6/28 16:19
 */
@Component
public class AuthenticationEntryPointImpl implements AuthenticationEntryPoint {



    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        String resp = R.errorJSONData(403, "未授权");
        response.setContentType("application/json;charset=UTF-8");
        response.getOutputStream().write(resp.getBytes());
    }
}
